#include "db.h"
#include "utiltool.h"
void setPatternDesc(RECORD* rec,char * str)
{
strcpy(rec->desc,str);
}
void setTerm(RECORD* rec,char * str)
{
strcpy(rec->term,str);
}

char * formatRecord(RECORD indata)
{
  //char*  buff=malloc(80*sizeof(char));	
 sprintf(BUFF, "%s,%02d,%02d,%02d,%02d,%02d,%02d,%02d\0",
 			indata.term,indata.red1,indata.red2,indata.red3,indata.red4,indata.red5,indata.red6,indata.blue);    
  return BUFF;
}
void   printRecord(RECORD indata)
{
char *buff=formatRecord(indata);
 printf("%s\n",buff);			
}
void Debug(char * msg)
{
if(DB_DEBUG)printf("%s\n", msg);	
}
int comp (const void * elem1, const void * elem2) 
{
    char f = *((char*)elem1);
    char s = *((char*)elem2);
    if (f > s) return  1;
    if (f < s) return -1;
    return 0;
}

char * sortBall(char * data,int length)
{
qsort (data, length, sizeof(char), comp);
return data;
}
int count=0;
void DisplayTimer(int  percent,int total)
{
char* signal[]={"|","/","-","\\"};
printf("%s %05d / %06d\r",signal[count%4],percent,total);

count++;
}
uint64_t getCurrentTimestamp()
{
struct timeval tv;
gettimeofday(&tv,NULL);

if(DB_DEBUG)printf("%ld raw seconds:\n",tv.tv_sec);
if(DB_DEBUG)printf("%d raw microseconds:\n",tv.tv_usec);
 uint64_t time_in_micros =( (uint64_t)1000 * (tv.tv_sec) )+ tv.tv_usec/1000;
if(DB_DEBUG)printf("%" PRIu64 "  real microseconds:\n",time_in_micros); 
return time_in_micros;
}

